import timeUtil from "./calendar";
const TAG = '[historyData]';
export default {
    data: {
        myDate: new Date(),
        list: [], // 日期列表
        historyChose: [],
        dateTop: "",
        curMonth: '',
        curDate: '今天',
        lan: 'zh',
        selectedId: 'abc',
        monthArrZh: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthArrEn: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
    },
    props: {
        // 数据列表
        whDataList: {
            type: Array,
            default: () => []
        },
        whData: String,
        // 周数组
        textTop: {
            type: Array,
            default: () => ["日", "一", "二", "三", "四", "五", "六"]
        },
        // 包含数据的日期列表
        isDataList: {
            type: Array,
            default: () => []
        },
    },
    onInit() {
        console.info(TAG + 'onInit')
        const month = new Date().getMonth()
        if (this.lan === 'zh') {
          this.curMonth = this.monthArrZh[month]
        } else {
          this.curMonth = this.monthArrEn[month]
        }
        this.$watch('isDataList', 'onIsDataListChange');
    },
    onReady() {
        this.myDate = new Date();
        this.getList(new Date(),this.isDataList, this.choseDate);
    },
    onIsDataListChange(isDataList) {
        this.getList(this.myDate, isDataList);
    },
    setClass(data) {
        let obj = {};
        obj[data.markClassName] = data.markClassName;
        return obj;
    },
    clickDay(item, index) {
        console.info(TAG + 'clickDay' + JSON.stringify(item));
        if (item.id === '') return
        this.curDate = item.date;
        this.selectedId = item.id;
        this.$emit('onClickDay', item.date)
    },
    ChoseMonth(date, isChosedDay = true) {
        date = timeUtil.dateFormat(date);
        this.myDate = new Date(date);
        this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
//        if (isChosedDay) {
//            this.getList(this.myDate, date, isChosedDay);
//        } else {
//            this.getList(this.myDate);
//        }
    },
    PreMonth(date, isChosedDay = true) {
        date = timeUtil.dateFormat(date);
        this.myDate = timeUtil.getOtherMonth(this.myDate, "preMonth");
        this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
//        if (isChosedDay) {
//            this.getList(this.myDate, date, isChosedDay);
//        } else {
//            this.getList(this.myDate);
//        }
//        this.$emit('onClickDay', this.curDate)
    },
    NextMonth(date, isChosedDay = true) {
        date = timeUtil.dateFormat(date);
        this.myDate = timeUtil.getOtherMonth(this.myDate, "nextMonth");
        this.$emit("changeMonth", timeUtil.dateFormat(this.myDate));
//        if (isChosedDay) {
//            this.getList(this.myDate, date, isChosedDay);
//        } else {
//            this.getList(this.myDate);
//        }
//        this.$emit('onClickDay', this.curDate)
    },
    forMatArgs() {
        let markDate = this.markDate;
        let markDateMore = this.markDateMore;
        markDate = markDate.map(k => {
            return timeUtil.dateFormat(k);
        });
        markDateMore = markDateMore.map(k => {
            k.date = timeUtil.dateFormat(k.date);
            return k;
        });
        return [markDate, markDateMore];
    },
    getList(date, isDataList,chooseDay, isChosedDay = true) {
        let arr = timeUtil.getMonthList(date);

        for(let i = 0; i < arr.length; i++) {
            let k = arr[i];
            if (isDataList.includes(k.date)) {
                k.isData = true
            }
        }

        this.list = JSON.parse(JSON.stringify(arr));
        this.dateTop = `${date.getFullYear()}年${date.getMonth() + 1}月`;
        let oneList = this.list.filter(item => item.id === '01')
        this.selectedId = oneList[0].id;
        this.curDate = oneList[0].date

    }
}